#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "t6Printer.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
	QString pn;

    ui->setupUi(this);

    printer = new t6Printer;
	printer->defaultPrinter(pn);
    ui->cbdprinter->addItem(pn);
}

MainWindow::~MainWindow()
{
    delete printer;
    delete ui;
}

void MainWindow::on_pbsend_clicked()
{
    QString str;
    QByteArray buf;

    str = ui->tecmd->toPlainText();
    buf = str.toStdString().data();
    printer->printRaw(buf);
}

void MainWindow::on_pbptext_clicked()
{
    QByteArray raw;
    QString str;
    int x,y;

    str = ui->letext->text();
    if (str.isEmpty())
        return;

    x = ui->sbx->value();
    y = ui->sby->value();
    raw = printer->makeHead();
    raw += printer->makeText(x, y, 15, str);
    raw += printer->makeEnd();
    printer->printRaw(raw);
}

void MainWindow::on_pbpqr_clicked()
{
    QByteArray raw;
    QString str;
    int x,y;

    str = ui->leqr->text();
    if (str.isEmpty())
        return;

    x = ui->sbx->value();
    y = ui->sby->value();
    raw = printer->makeHead();
    raw += printer->makeQrCode(x, y, 15, str);
    raw += printer->makeEnd();
    printer->printRaw(raw);
}

void MainWindow::on_pbstatus_clicked()
{
    QString s;

    s = s.sprintf("%d", printer->status());

    ui->lestatus->setText(s);
}
